package cn.edu.ctbu.students.service;

import cn.edu.ctbu.students.dao.StudentRepository;
import cn.edu.ctbu.students.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class StudentService {
    @Autowired

    public StudentRepository studentRepository;

    public List<Student> getAll() {
        return studentRepository.findAll();
    }


    public Student add(Student student) {
        return studentRepository.save(student);
    }

    public Student update(Student student) {
        return studentRepository.save(student);
    }

    public void delete(int studentId) {
        studentRepository.deleteById(studentId);
    }
    public Student findById(int studentId) {
        return studentRepository.findById(studentId).get();
    }
}
